package com.hc.webservice;

import java.io.File;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import com.hc.DTO.TokenDTO;
import com.hc.constants.Constants;

public class ServiceHandlerUpload {
	static String responsecontent = null;

	public String uploadService(ArrayList<String> arrlink, TokenDTO token,
			String description) {
		DefaultHttpClient httpclient = new DefaultHttpClient();
		HttpPost postRequest = new HttpPost(Constants.URL_UPLOAD);

		postRequest.setHeader("Authorization", token.getToken_type() + " "
				+ token.getAccess_token());
		HttpEntity httpEntity = null;
		try {
			MultipartEntity reqEntity = new MultipartEntity();
			reqEntity.addPart("Desc", new StringBody(description));
			reqEntity.addPart("CountryCode", new StringBody("1"));

			for (String pathImg : arrlink) {
				reqEntity.addPart("filename", new FileBody(new File(pathImg)));
			}

			postRequest.setEntity(reqEntity);

			HttpResponse response = httpclient.execute(postRequest);
			httpEntity = response.getEntity();
			responsecontent = EntityUtils.toString(httpEntity);

		} catch (Exception e) {
			// TODO: handle exception
		}
		return responsecontent;
	}
}
